define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'expand/modelsp/index' + location.search,
                    //add_url: 'expand/modelsp/add',
                    edit_url: 'expand/modelsp/edit',
                    //del_url: 'expand/modelsp/del',
                    multi_url: 'expand/modelsp/multi',
                    import_url: 'expand/modelsp/import',
                    table: 'hear_say_products',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'productId',
                sortName: 'productId',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'productId', title: __('Id')},
                        {field: 'productName', title: __('名称')},
                        {field: 'cover', title: __('图片'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'periodName', title: __('学阶')},
                        {field: 'gradeName', title: __('年级')},
                        // {field: 'status', title: __('状态'), formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table,
                        events: Table.api.events.operate,
                        buttons: [{
                            name: 'detail',
                            text: __('章节'),
                            icon: 'fa fa-list',
                            classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                            extend:'data-area=["90%","95%"]',
                            url: 'expand/modelsp/chapter?ids={productId}'
                        }],
                        formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        chapter: function () {
            console.log(Table);
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'expand/modelsp/chapter' + location.search,
                    table: 'hear_say_catalogues',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                // pk: 'productId',
                sortName: 'displayOrder',
                sortOrder: 'asc',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'name', title: __('名称')},
                        {field: 'displayOrder', title: __('排序'),sortable:true},
                        {field: 'operate', title: __('Operate'), table: table,
                        events: Table.api.events.operate,
                        buttons: [{
                            name: 'detail',
                            text: __('模拟题'),
                            icon: 'fa fa-list',
                            classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                            extend:'data-area=["90%","95%"]',
                            url: 'expand/modelsp/chapterdetail?ids={id}&&pid={productId}'
                        }],
                        formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
